Skip to content

fix: cache validation, narrow invalidation, ISR pre-render, robust CI redis wait (#1099, #1100, #1101, #1102) - #1152

Merged
nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
Mirabel64:fix/mirabel64-1099-1102
Sep 28, 2026
Merged

nanaf6203-bit merged 2 commits into
MettaChain:mainfrom
Mirabel64:fix/mirabel64-1099-1102

Conversation

@Mirabel64

Copy link
Copy Markdown
Contributor

Summary

Resolves the four open issues assigned to @Mirabel64 in one PR.

Closes #1099
Closes #1100
Closes #1101
Closes #1102

Changes

#1102 — Pre-generate popular property IDs in generateStaticParams

  • src/lib/propertyServiceServer.ts: new getPopularPropertyIds(limit = 20) that returns featured property ids (falling back to the full catalogue when nothing is flagged featured).
  • src/app/properties/[id]/page.tsx: generateStaticParams now returns real { id } entries instead of []. dynamicParams stays default (true), so non-listed ids are still generated on demand and revalidated by ISR (revalidate = 60).

#1101 — Validate JSON parsed from Redis before trusting cached payloads

  • src/types/propertySchemas.ts: new zod schemas mirroring the Property domain types (propertySchema, propertySearchResultSchema, autocompleteResultsSchema, cacheStatsSchema).
  • src/lib/redisCache.ts: every JSON.parse of a cache payload now goes through parseCached, which validates against a schema. Malformed or shape-mismatched entries are discarded (treated as a miss) instead of being cast to Property/SearchResult. Failures are logged and counted (cache:hit_rate:invalid, exposed as invalid in getStats).

#1100 — Property updates no longer flush the entire cache

  • src/lib/redisCache.ts: writes maintain a per-property reverse index (index:property:<id>), and invalidateProperty deletes only the keys that embed that property, falling back to the old narrow pattern scan only when the index is missing. Also fixed invalidatePattern, whose DEL args were double-prefixed by ioredis and silently missed.
  • src/lib/blockchainCacheInvalidator.ts: only membership-changing events (PropertyCreated, PropertyDelisted) flush listing:*/search:*; updates use the narrow index path.
  • src/app/api/properties/route.ts: POST invalidates narrowly when an id is present, otherwise a listing/search flush.
  • docs/cache-api.md: documented the new behaviour plus before/after hit-rate notes.

#1099 — Harden the Redis wait step in CI

  • .github/workflows/ci.yml: replaced the fragile docker ps --filter ancestor=redis:7-alpine lookup with a deterministic lookup by published port (then service name), a bounded 30×2s retry, and a clear failure path that dumps docker ps -a and container logs.

Tests

  • src/lib/__tests__/redisCache.test.ts: added poisoned-payload rejection, malformed listing rejection, stats shape (including invalid), and a narrow-invalidation test asserting an unrelated listing survives an update.
  • src/lib/__tests__/propertyServiceServer.test.ts: asserts getPopularPropertyIds returns real, pre-renderable ids and respects the limit.
Test Suites: 2 passed, 2 total
Tests:       8 passed, 8 total

Typecheck shows no new errors versus main (the repo has pre-existing errors in this environment's stale node_modules; a before/after diff of tsc output is unchanged apart from line-number shifts).

Notes

…y pages, robust CI redis wait

Resolves the four issues assigned to Mirabel64:

- MettaChain#1101: validate Redis cache payloads against zod schemas before trusting
  them; corrupted/stale entries are discarded and counted as invalid + miss
  instead of being cast to Property/SearchResult.
- MettaChain#1100: add a per-property key index so mutations evict only the detail,
  listing and search keys that embed the affected property; full flush is
  now explicit. Document the hit-rate impact in docs/cache-api.md.
- MettaChain#1102: generateStaticParams now returns real featured property ids so the
  popular detail pages are pre-rendered; the rest stay on-demand + ISR.
- MettaChain#1099: replace the fragile `docker --filter ancestor` redis wait with a
  deterministic published-port/name lookup and actionable failure logs.

🤖 Generated with Codebuff
Co-Authored-By: Codebuff <noreply@codebuff.com>
@drips-wave

drips-wave Bot commented Sep 27, 2026

Copy link
Copy Markdown

@Mirabel64 Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits.

You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀

Learn more about application limits

@nanaf6203-bit nanaf6203-bit left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@nanaf6203-bit
nanaf6203-bit merged commit b9ccd05 into MettaChain:main Sep 28, 2026
0 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

2 participants